﻿using System; 
using System.Collections.Generic;
using System.Text;
using AJAXChatClient.Flash.Net;

namespace AJAXChatClient.Flash.Media
{
    public class Sound
    {
        public Sound() : this(null, null) { }

        public Sound(URLRequest stream) : this(stream, null) { }

        public Sound(URLRequest stream, SoundLoaderContext context)
        {
        }

        public void Load(URLRequest stream)
        {
            this.Load(stream, null);
        }

        public void Load(URLRequest stream, SoundLoaderContext context)
        {
        }

        public SoundChannel Play()
        {
            return this.Play(0, 0, null);
        }

        public SoundChannel Play(float startTime)
        {
            return this.Play(startTime, 0, null);
        }

        public SoundChannel Play(float startTime, int loops)
        {
            return this.Play(startTime, loops, null);
        }

        public SoundChannel Play(float startTime, int loops, SoundTransform sndTransform)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Returns the currently available number of bytes in this sound object.
        /// </summary>
        public uint BytesLoaded
        {
            get;
        }

        /// <summary>
        /// Returns the total number of bytes in this sound object.
        /// </summary>
        public int BytesTotal
        {
            get;
        }

        /// <summary>
        /// Returns the buffering state of external MP3 files.
        /// </summary>
        public bool IsBuffering
        {
            get;
        }

        /// <summary>
        /// Indicates if the <see cref="URL"/> property has been truncated.
        /// </summary>
        public bool IsURLInaccessible
        {
            get;
        }

        /// <summary>
        /// The length of the current sound in milliseconds.
        /// </summary>
        public float Length
        {
            get;
        }

        /// <summary>
        /// The URL from which this sound was loaded.
        /// </summary>
        public string URL
        {
            get;
        }

        public class CompleteEventArgs
        {
            public readonly bool Bubbles = false;
            /// <summary>
            /// false; there is no default behavior to cancel.
            /// </summary>
            public readonly bool Cancelable = false;
            /// <summary>
            /// The object that is actively processing the Event object with an event listener.
            /// </summary>
            public readonly object CurrentTarget;
            /// <summary>
            /// The network object that has completed loading.
            /// </summary>
            public readonly object Target;
        }

        public delegate void CompleteEventHandler(CompleteEventArgs eventArgs);

        public event CompleteEventHandler CompleteEvent;

        public class ID3EventArgs
        {
            public readonly bool Bubbles = false;
            /// <summary>
            /// false; there is no default behavior to cancel.
            /// </summary>
            public readonly bool Cancelable = false;
            /// <summary>
            /// The object that is actively processing the Event object with an event listener.
            /// </summary>
            public readonly object CurrentTarget;
            /// <summary>
            /// The Sound object loading the MP3 for which ID3 data is now available.
            /// The <see cref="Target"/> is not always the object in the display list 
            /// that registered the event listener. Use the <see cref="CurrentTarget"/> property 
            /// to access the object in the display list that is currently processing the event.
            /// </summary>
            public readonly object Target;
        }

        public delegate void ID3EventHandler(ID3EventArgs eventArgs);

        /// <summary>
        /// Dispatched by a Sound object when ID3 data is available for an MP3 sound.
        /// </summary>
        public event ID3EventHandler ID3Event;

        public class IOErrorEventArgs
        {
            public readonly bool Bubbles = false;
            /// <summary>
            /// false; there is no default behavior to cancel.
            /// </summary>
            public readonly bool Cancelable = false;
            /// <summary>
            /// The object that is actively processing the Event object with an event listener.
            /// </summary>
            public readonly object CurrentTarget;
            /// <summary>
            /// A reference number associated with the specific error.
            /// </summary>
            public readonly int ErrorID;
            /// <summary>
            /// The network object experiencing the input/output error.
            /// </summary>
            public readonly object Target;
            /// <summary>
            /// Text to be displayed as an error message.
            /// </summary>
            public readonly string Text;
        }

        public delegate void IOErrorEventHandler(IOErrorEventArgs eventArgs);

        /// <summary>
        /// Dispatched when an input/output error occurs that causes a send or receive operation to fail.
        /// </summary>
        public event IOErrorEventHandler IOErrorEvent;
    }
}
